//SymbianEngine.h : Includes the implementation for the controlling game engine of this game
// this is where all initialization takes place and finally where the entire game will end
//$Id: SymbianEngine.cpp 49 2009-09-28 22:28:07Z brwarner2 $
#include "stdafx.h"
#include "SymbianEngine.h"
#include "ResourceManager.h"
#include "StateManager.h"

//Include BUG libraries
#include <bug/libs.h>
#ifndef _DEBUG
#pragma comment(lib, "gamemonkey.lib")
#else
#pragma comment(lib, "gamemonkey_d.lib")
#endif

//State registration function
void RegisterGameStates( CStateManager* );

CSymbianEngine::CSymbianEngine(void) : bug::game::IGameEngine( GetModuleHandle(0), "SymbianEngine" ), 
m_bFirstUpdate(true), m_pStateManager(0)
{
	//Create state manager
	m_pStateManager = new CStateManager();
}

CSymbianEngine::~CSymbianEngine(void)
{
}

void CSymbianEngine::Release(void)
{
	//Destroy the state manager
	delete m_pStateManager;
	m_pStateManager = 0;

	//Destroy the resource manager
	delete Resource();
	Resource(0);

	//Destroy the sprite
	delete m_pSprite;
	m_pSprite = 0;
}

void CSymbianEngine::Update( float fElapsed, float fTotal, bug::input::IInputDevice* pDevice )
{
	if(m_bFirstUpdate) {
		//Disable the mouse catching function
		pDevice->SetMode( bug::input::DEVICE_MOUSE, false );

		//Save input device
		Resource()->m_pInputDevice = pDevice;
	}

	//Update the state manager
	m_pStateManager->Update(fElapsed, fTotal);
}

void CSymbianEngine::Render( bug::render::IRenderDevice* pDevice )
{
	m_pStateManager->Render();
}

void CSymbianEngine::Load( bug::render::IRenderDevice* pDevice )
{
	using namespace RemoteLogger;

	//Setup resource manager
	CResourceManager* pRes = new CResourceManager();
	pRes->m_pRenderDevice = pDevice;
	pRes->m_pAudioDevice = GetAudioDevice();
	pRes->m_pEngine = this;

	//Create sprite
	m_pSprite = new bug::render::CSprite(pDevice);
	pRes->m_pSprite = m_pSprite;

	//Save singleton
	Resource(pRes);

	//Register game states
	RegisterGameStates(m_pStateManager);

	//Set current state
	m_pStateManager->ChangeState("AreaView",true);
}

//Define entry point for program
PROGRAM_ENTRY( CSymbianEngine, "Symbian Adventures" )